<?php

namespace App\Http\Controllers\Home;

use App\Http\Controllers\Controller;
use App\MovieModel;
use App\TypeModel;
use Illuminate\Http\Request;

class HomeController extends Controller
{
    public function home1(Request $request)
    {
        $types = TypeModel::take(8)->get();
        $cols = ["movie.*","type.name_ch as typeName","country.name_ch as countryName"];
        $recommend = MovieModel::leftjoin("type","movie.type","type.id")->leftjoin("country","movie.country","country.id")->orderBy("updated_at","DESC")->take(4)->get($cols);
        $rightTop = MovieModel::orderBy("score","DESC")->first();
        $rightBottom = MovieModel::find(5);
        $movies = MovieModel::orderBy("id","DESC")->take(10)->get();
        return view("home.home",compact("types","recommend","rightTop","rightBottom","movies"));
    }

    public function play(Request $request)
    {
        $types = TypeModel::take(8)->get();
        $id = $request->input("id");
        $cols = ["movie.*","type.name_ch as typeName","country.name_ch as countryName"];
        $movie = MovieModel::leftjoin("type","movie.type","type.id")->leftjoin("country","movie.country","country.id")->where("movie.id",$id)->first($cols);
//        $recommend = MovieModel::where("type",$movie->type)->take(4)->get();
        return view("home.play",compact("types","movie"));
    }
}
